package main.test.SparkAPI.Baics

// unapply method usage example
object drink{
  def unapply(drk:drink):Option[(Double,Double)] = {
    val nutriFacts = drk.loadNtriFacts()
    println("hello welcom to unapply")
    Some((nutriFacts.saturatedFat,nutriFacts.sugars))
  }

}

class drink( name: String,
                  brand: String,
                  size: Double /* milliliter */){

  val fatThreshold: Double = 7
  val sugarThreshold: Double = 74
  def loadNtriFacts(): NutritionFacts = NutritionFacts(1,20,3,4)

  def danalyze(drinkdr: drink): Label = drinkdr match {
    case drink(fat, sugar)
      if fat < fatThreshold &&
        sugar < sugarThreshold => LowSaturatedFatAndSugar
    case drink(fat, _) if fat < fatThreshold => LowSaturatedFat
    case drink(_, sugar) if sugar < sugarThreshold => LowSugar
    case _ => HighSaturatedFatAndSugar
  }


}
